package org.game.db.bean;

import org.game.db.cache.RoleCache;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import org.apache.commons.lang3.ArrayUtils;
import static org.game.db.StaticResource.ReserveDateRecordResource.*;
import com.sojoys.artifact.tools.SK_String;
import com.xiaoleilu.hutool.util.StrUtil;
import org.game.db.cache.ReserveDateRecordCache;
import com.sojoys.artifact.build.data.base.BasePojo;
import java.sql.SQLException;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import org.game.db.cache.PlayerCache;
import java.sql.ResultSet;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.game.db.StaticResource.ReserveDateRecordResource.*;
/**
 * 预定约会记录
 */
public class ReserveDateRecord extends BasePojo<ReserveDateRecord> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[3];
	
	/**
	* id
	*/
	private long id;
	
	/**
	* 约会配置id
	*/
	private int datingCid;
	
	/**
	* 时间段
	*/
	private int[] timeFrame;
	
	/**
	* 状态 0：无约会 1：有邀请 2：接受邀请
	*/
	private int state;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	/**
	* 玩家id
	*/
	private int playerId;
	
	/**
	* 看板娘id
	*/
	private long roleId;
	
	/**
	* 约会次数
	*/
	private int datingCount;
	
	/**
	* 接受邀请时间
	*/
	private java.util.Date datingTime;
	
	/**
	* 上次刷新时间
	*/
	private java.util.Date lastRefreshTime;
	
	
	@Deprecated
	public static ReserveDateRecord builder() {
		ReserveDateRecord reserveDateRecord = new ReserveDateRecord();
		return reserveDateRecord;
	}
	
	@Deprecated
	public ReserveDateRecord() {
		super();
	}
	
	public ReserveDateRecord(long id, int datingCid, int[] timeFrame, int state, int playerId, long roleId, int datingCount, java.util.Date datingTime, java.util.Date lastRefreshTime) {
		super();
		this.id = id;
		this.datingCid = datingCid;
		this.timeFrame = timeFrame;
		this.state = state;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
		this.playerId = playerId;
		this.roleId = roleId;
		this.datingCount = datingCount;
		this.datingTime = datingTime;
		this.lastRefreshTime = lastRefreshTime;
	}
	
	/**
	 * id
	 */
	public long getId() {return id;}
	
	/**
	 * id
	 */
	public ReserveDateRecord setId(long id) {this.id = id;return this;}
	
	/**
	 * 约会配置id
	 */
	public int getDatingCid() {return datingCid;}
	
	/**
	 * 约会配置id
	 */
	public ReserveDateRecord setDatingCid(int datingCid) {this.datingCid = datingCid;return this;}
	
	/**
	 * 时间段
	 */
	public int[] getTimeFrame() {return timeFrame;}
	
	/**
	 * 时间段
	 */
	public ReserveDateRecord setTimeFrame(int[] timeFrame) {this.timeFrame = timeFrame;return this;}
	
	/**
	 * 时间段
	 */
	public String getTimeFrameString() {
	    return toJSONString(timeFrame);
	}
	
	/**
	 * 时间段
	 */
	public int[] initTimeFrameString(String str) {
		return forJsonObject(str,int[].class);
	}	
	/**
	 * 状态 0：无约会 1：有邀请 2：接受邀请
	 */
	public int getState() {return state;}
	
	/**
	 * 状态 0：无约会 1：有邀请 2：接受邀请
	 */
	public ReserveDateRecord setState(int state) {this.state = state;return this;}
	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected ReserveDateRecord setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected ReserveDateRecord setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	/**
	 * 玩家id
	 */
	public int getPlayerId() {return playerId;}
	
	/**
	 * 玩家id
	 */
	public ReserveDateRecord setPlayerId(int playerId) {this.playerId = playerId;return this;}
	
	/**
	 * 看板娘id
	 */
	public long getRoleId() {return roleId;}
	
	/**
	 * 看板娘id
	 */
	public ReserveDateRecord setRoleId(long roleId) {this.roleId = roleId;return this;}
	
	/**
	 * 约会次数
	 */
	public int getDatingCount() {return datingCount;}
	
	/**
	 * 约会次数
	 */
	public ReserveDateRecord setDatingCount(int datingCount) {this.datingCount = datingCount;return this;}
	
	/**
	 * 接受邀请时间
	 */
	public java.util.Date getDatingTime() {return datingTime;}
	
	/**
	 * 接受邀请时间
	 */
	public ReserveDateRecord setDatingTime(java.util.Date datingTime) {this.datingTime = datingTime;return this;}
	
	/**
	 * 上次刷新时间
	 */
	public java.util.Date getLastRefreshTime() {return lastRefreshTime;}
	
	/**
	 * 上次刷新时间
	 */
	public ReserveDateRecord setLastRefreshTime(java.util.Date lastRefreshTime) {this.lastRefreshTime = lastRefreshTime;return this;}
	
	
	// 代理
	private org.game.db.proxy.bean.ReserveDateRecordProxy reserveDateRecordProxy = new org.game.db.proxy.bean.ReserveDateRecordProxy().build(this);
	
	public org.game.db.proxy.bean.ReserveDateRecordProxy getReserveDateRecordProxy(){return reserveDateRecordProxy;}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.datingCid;
        values[2] = this.timeFrame;
        values[3] = this.state;
        values[4] = this.createDate;
        values[5] = this.modifiedDate;
        values[6] = this.playerId;
        values[7] = this.roleId;
        values[8] = this.datingCount;
        values[9] = this.datingTime;
        values[10] = this.lastRefreshTime;
        return values;
	}
	
	public ReserveDateRecord deepCopy(){
		ReserveDateRecord reserveDateRecord = null;
		try {
			reserveDateRecord = (ReserveDateRecord) super.clone();
		    reserveDateRecord.setTimeFrame(ToolCopy.copyObject(this.timeFrame));
		    reserveDateRecord.setCreateDate(ToolCopy.copyObject(this.createDate));
		    reserveDateRecord.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    reserveDateRecord.setDatingTime(ToolCopy.copyObject(this.datingTime));
		    reserveDateRecord.setLastRefreshTime(ToolCopy.copyObject(this.lastRefreshTime));
		    // 克隆索引
		    reserveDateRecord.indexValues = ArrayUtils.clone(indexValues);
			return reserveDateRecord;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return reserveDateRecord;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.datingCid);
        map.put(keys[2], this.timeFrame);
        map.put(keys[3], this.state);
        map.put(keys[4], this.createDate);
        map.put(keys[5], this.modifiedDate);
        map.put(keys[6], this.playerId);
        map.put(keys[7], this.roleId);
        map.put(keys[8], this.datingCount);
        map.put(keys[9], this.datingTime);
        map.put(keys[10], this.lastRefreshTime);
        return map;
    }
    
    protected ReserveDateRecord createForMap(Object[] keys,Map map){
   		this.id = (long)map.get(keys[0]);
   		this.datingCid = (int)map.get(keys[1]);
   		this.timeFrame = (int[])map.get(keys[2]);
   		this.state = (int)map.get(keys[3]);
   		this.createDate = (java.util.Date)map.get(keys[4]);
   		this.modifiedDate = (java.util.Date)map.get(keys[5]);
   		this.playerId = (int)map.get(keys[6]);
   		this.roleId = (long)map.get(keys[7]);
   		this.datingCount = (int)map.get(keys[8]);
   		this.datingTime = (java.util.Date)map.get(keys[9]);
   		this.lastRefreshTime = (java.util.Date)map.get(keys[10]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.datingCid);
        obj.put(keys[2], this.timeFrame);
        obj.put(keys[3], this.state);
        obj.put(keys[4], this.createDate);
        obj.put(keys[5], this.modifiedDate);
        obj.put(keys[6], this.playerId);
        obj.put(keys[7], this.roleId);
        obj.put(keys[8], this.datingCount);
        obj.put(keys[9], this.datingTime);
        obj.put(keys[10], this.lastRefreshTime);
        return obj;
    }
    
    protected ReserveDateRecord createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getLongValue(keys[0]);
	    this.datingCid = obj.getIntValue(keys[1]);
		this.timeFrame = obj.getObject(keys[2],int[].class);
	    this.state = obj.getIntValue(keys[3]);
	    this.createDate = obj.getDate(keys[4]);
	    this.modifiedDate = obj.getDate(keys[5]);
	    this.playerId = obj.getIntValue(keys[6]);
	    this.roleId = obj.getLongValue(keys[7]);
	    this.datingCount = obj.getIntValue(keys[8]);
	    this.datingTime = obj.getDate(keys[9]);
	    this.lastRefreshTime = obj.getDate(keys[10]);
        return this;
    }
    
    
    public ReserveDateRecord createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getLong(SOURCE_COLUMN_NAMES[0]);
	    this.datingCid = rs.getInt(SOURCE_COLUMN_NAMES[1]);
		this.timeFrame = forJsonObject(rs.getString(SOURCE_COLUMN_NAMES[2]),int[].class);
	    this.state = rs.getInt(SOURCE_COLUMN_NAMES[3]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[4]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[5]);
	    this.playerId = rs.getInt(SOURCE_COLUMN_NAMES[6]);
	    this.roleId = rs.getLong(SOURCE_COLUMN_NAMES[7]);
	    this.datingCount = rs.getInt(SOURCE_COLUMN_NAMES[8]);
	    this.datingTime = rs.getTimestamp(SOURCE_COLUMN_NAMES[9]);
	    this.lastRefreshTime = rs.getTimestamp(SOURCE_COLUMN_NAMES[10]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeLong(this.id);
	    byteBuf.writeInt(this.datingCid);
	    byteBuf.writeObject(this.timeFrame);
	    byteBuf.writeInt(this.state);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
	    byteBuf.writeInt(this.playerId);
	    byteBuf.writeLong(this.roleId);
	    byteBuf.writeInt(this.datingCount);
	    byteBuf.writeDate(this.datingTime);
	    byteBuf.writeDate(this.lastRefreshTime);
    }
	
	protected ReserveDateRecord readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readLong(null);
	    this.datingCid = byteBuf.readInt(null);
	    this.timeFrame = byteBuf.readIntArray(null);
	    this.state = byteBuf.readInt(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    this.playerId = byteBuf.readInt(null);
	    this.roleId = byteBuf.readLong(null);
	    this.datingCount = byteBuf.readInt(null);
	    this.datingTime = byteBuf.readDate(null);
	    this.lastRefreshTime = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	/** 取得[player]*/
	public Player getPlayerPkPlayerId(){
		return PlayerCache.me().getById(playerId);
	}
	/** 取得[role]*/
	public Role getRolePkRoleId(){
		return RoleCache.me().getById(roleId);
	}
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public ReserveDateRecord insert(){
    	return ReserveDateRecordCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public ReserveDateRecord update(){
    	return ReserveDateRecordCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return ReserveDateRecordCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public ReserveDateRecord insertAndFlush(){
    	return ReserveDateRecordCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public ReserveDateRecord updateAndFlush(){
    	return ReserveDateRecordCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return ReserveDateRecordCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public ReserveDateRecord syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getRoleId()).e();
		indexValues[2] = SK_Plus.b(getPlayerId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((long)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}